#include "mainscene.h"
#include "ui_mainscene.h"
#include<QPainter>
#include "mypushbutton.h"
#include<QDebug>
#include<QTimer>
#include<QSound>
MainScene::MainScene(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainScene)
{
    ui->setupUi(this);
    //准备音效
    QSound *startSound = new QSound(":/res/TapButtonSound.wav",this);
    //设置固定大小
        this->setFixedSize(320,588);
    //设置应用图片
        this->setWindowIcon(QPixmap(":/res/Coin0001.png"));//题头部分的名字+金币
    //设置窗口标题
        this->setWindowTitle("翻金币");
    //创建第二个选关场景
    this->chooseScene=new ChooseLevelScene;
    //创建开始按钮
        MyPushButton * startBtn = new MyPushButton(":/res/MenuSceneStartButton.png");
        startBtn->setParent(this);
        startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);

        connect(startBtn,&MyPushButton::clicked,[=](){
            startSound->play(); //开始音效
            startBtn->zoom1();
            startBtn->zoom2();
            //延时0.5秒后 进入选择场景
                   QTimer::singleShot(500, this,[=](){
                        this->hide();
                        chooseScene->show();
                    });
        });
        //监听选择场景的返回按钮
        connect(this->chooseScene,&ChooseLevelScene::ChooseSceneBack,[=](){
                this->chooseScene ->hide();
                        this->show();
                    });



}
void MainScene::paintEvent(QPaintEvent *)
{
    //创建画家，指定绘图设备
    QPainter painter(this);
    //创建QPixmap对象
    QPixmap pix;
    //加载图片
    pix.load(":/n/res/cc756d276c1353f58740b209dd7616df.png");
    //绘制背景图
    painter.drawPixmap(0,0,this->width(),this->height(),pix);


    //加载标题
    pix.load(":/res/Title.png");
    //缩放图片
    pix = pix.scaled(pix.width()*0.5,pix.height()*0.5);
    //绘制标题
    painter.drawPixmap( 10,30,pix.width(),pix.height(),pix);
}


MainScene::~MainScene()
{
    delete ui;
}
